package com.controller;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.service.StuService;

@Controller
public class ThymeleafAction {
	// 测试常用th属性
	@Autowired
	private StuService stu;
	@RequestMapping("/thymeleaf")
	public String thymeleaf(ModelMap map) {
		map.put("thText", "th:text 设置文本内容 <b>加粗也没用因为不会转义</b>");
		map.put("thUText", "th:utext 设置文本内容 <b>加粗有用,会转义</b>");
		map.put("thValue", "thValue 设置当前元素的value值");
		map.put("thEach", Arrays.asList("香蕉", "芒果", "桃子", "杏", "苹果"));
		map.put("thIf", "msg is not null");
		map.put("thObject", stu.getStuByid(1));
		return "thymeleaf-pages/demo1";
	}

	// 测试常用内置方法
	@RequestMapping("/varexpressions")
	public String varexpressions(ModelMap map) {
		map.put("xxxStr", "this is a cat");
		map.put("xxxBool", false);
		map.put("xxxArray", new Integer[] { 1, 2, 3, 4 });
		map.put("xxxList", Arrays.asList(1, 3, 2, 4, 0));

		Map<String, Object> xxxMap = new HashMap<String, Object>();
		xxxMap.put("第一", "陈聪");
		xxxMap.put("第二", "范鸽");
		map.put("xxxMap", xxxMap);

		map.put("xxxDate", new Date());
		map.put("xxxNum", 888.888D);
		return "thymeleaf-pages/demo2";
	}

	@GetMapping("/main")
	public String test() {
		return "main";
	}
}
